function initMain(){
	loadPage({title:'管理首页',url:mainUrl});
}
/*定义应用程序整体框架*/

var ucmaiApp = function(){this.init();}

var managehome = {
	id:'managehome',
	title:'管理首页',
	layout:'fit',
	border:false,
	items:[new Ext.Panel({
		contentEl:'center',
		border:false,
		layout:'fit',
		html:'<iframe src="'+mainUrl+'" marginheight="0" marginwidth="0" scrolling="scroll" frameborder="0" width="100%" height="'+ sysCenterHeight +'"></iframe>'
	})]
};

Ext.extend(ucmaiApp, Ext.util.Observable, {
	init:function(){
		zyt.Permit();
		//zyt.setStyle(zyt.cookies.get("UCM_THEME"));

		var toppanel = new Ext.BoxComponent({
			region:'north',
			cls: 'header',
			el: 'north',
			height:30
		});

		var westpanel = new Ext.Panel({
			region:'west',
			id:'west-panel',
			hideMode:'offsets',
			title:'<a href="javascript:initMain();">管理首页</a>',
			width: 170,
			collapsible: true,
			margins:'0 0 0 5',
			layout:'fit',
			html:'<div id="tree-div" style="height:100%;width:100%;overflow:auto;"></div>'
		});

		var eastpanel = new Ext.TabPanel({
			region:'center',
			id: 'mainpanel',
			activeTab:0,
			enableTabScroll:true,
			tabPosition:"top",
			resizeTabs:true,//是否可以改变tab的尺寸，默认为false。
			deferredRender : true,
			plugins: new Ext.ux.TabCloseMenu(),
			defaults: {autoScroll:true},
			enableTabScroll:true,
			layoutOnTabChange:true,
			items:[managehome]
		});

		var viewport = new Ext.Viewport({
			layout:'border',
			items:[toppanel,westpanel,eastpanel,{
				region: 'south',
				height: 25,
				border: false,
				html: '<div id="footer" unselectable="on">Copyright <span>©</span> 2011-2012 <a href="/" target="_blank"></a> 版权所有.</div>'
			}]
		});
		var toptb = new Ext.Toolbar(['<div id="logo"><img src="/jlib/img/logo.png" id="logo_img"/></div>','->','<div id="TimePeriod"></div>','<div id="user"><font color="red">' + username + '</font>&nbsp;欢迎您！</div>','&nbsp;','现在时间：',
				'<div id="date"></div>','&nbsp;',
				{
					text: '修改资料',
					iconCls:'user',
					handler:function(){
						zyt.ImportMod('userinfo_x_ext.js', function(){
							var oUserInfo = new UserInfo();
							oUserInfo = null;
						});
					}
				},{
					text: '修改密码',
					iconCls:'user',
					handler:function(){
						zyt.ImportMod('userpass_x_ext.js', function(){
							var oUserPass = new UserPass();
							oUserPass = null;
						});
					}
				},{
					text:'主题',
					iconCls:'theme',
					menu:new Ext.menu.Menu({
						items:[{
							text:'默认主题',
							handler:function(){
								zyt.cookies.set('UCM_THEME','');
								zyt.setStyle('');
							}
						},
						{
							text:'绿色主题',
							handler:function(){
								zyt.cookies.set('UCM_THEME','green');
								zyt.setStyle('green');
							}
						},{
							text:'兰色主题',
							handler:function(){
								zyt.cookies.set('UCM_THEME','blue');
								zyt.setStyle('blue');
							}
						},{
							text:"橙色主题",
							handler:function(){
								zyt.cookies.set('UCM_THEME','orange');
								zyt.setStyle('orange');
								
							}
						},{
							text:"红色5主题",
							handler:function(){
								zyt.cookies.set('UCM_THEME','red5');
								zyt.setStyle('red5');
							}
						},{
						
							text:'银色主题',
							handler:function(){
								zyt.cookies.set('UCM_THEME','silverCherry');
								zyt.setStyle('silverCherry');
							}
							
						}]
					})
				},
				{text:'帮助',iconCls:'help',handler:function(){Ext.alert('构建中...');}},
				{text:'退出',iconCls:'exit',handler:function(){
					showLoading("系统正在销毁缓存对象并退出中，请稍侯...","正在退出中...");
					zyt.ajax(serverUrl_logout, {action:'logout'}, function() {
						window.location.href = serverUrl_login;
					});
				}}]
		);
		
		toptb.render('top');
		//toptb.add();

		//var userid = 0;
		//var ss = document.getElementsByTagName('script');
//		for(i=0;i<ss.length;i++){
//			if(ss[i].src.indexOf('SysFramework.js?userid=') != -1){
//				userid = ss[i].src.split('SysFramework.js?userid=')[1];
//				break;
//			}
//		}
		//userid = zyt.cookies.get("ali");
		//userid = 1;
		var Tree = Ext.tree;
		this.tree = new Tree.TreePanel({
			id:'app_main_tree',
			el:'tree-div',
			iconCls:'set',
			border:false,
			animate:false,
			autoScroll:true,
			containerScroll: true,
			rootVisible:false,
			loader:new Ext.tree.TreeLoader({ 
				dataUrl:'/profile/' + userid + 'sf.shtml'
			})
		});
		
		this.root = new Tree.AsyncTreeNode();   
		this.tree.setRootNode(this.root);
		this.tree.on('click',function(node){
			//Ext.Msg.alert('',node.id);
			if(!node.isLeaf()){node.toggle();}
		});

		this.tree.render();
		this.root.expand(false);

		zyt.getSysUser();
		//主题设置
		//Cookies.set('UCM_THEME','blue');
		//setStyle('blue');
		(function showDate(){
			var now = new Date();
			var hour = now.getHours();
			var sWwords = "";
			if (hour < 6){
				sWwords = "凌晨好";
			}else if(hour < 9){
				sWwords = "早上好";
			}else if (hour < 12){sWwords = "上午好";
			}else if (hour < 14){sWwords = "中午好";
			}else if (hour < 17){sWwords = "下午好";
			}else if (hour < 19){sWwords = "傍晚好";
			}else if (hour < 22){sWwords = "晚上好";
			}else {sWwords = "夜里好";} 
			Ext.get("TimePeriod").dom.innerHTML = sWwords + '，';
			Ext.get('date').dom.innerHTML = now.toLocaleDateString() + '&nbsp;'+ now.toLocaleTimeString();
			setTimeout(showDate,1000);
		})();
	}
});
Ext.ux.TabCloseMenu = function(){
	var tabs, menu, ctxItem;
	this.init = function(tp){
		tabs = tp;//mainpanel
		tabs.on('contextmenu', onContextMenu);
	}

	function onContextMenu(ts, item, e){//ts:mainpanel对象,
		if(!menu){ // create context menu on first right click
			menu = new Ext.menu.Menu([{
　　　　　　　　text:"关闭当前页",
				iconCls:'remove',
　　　　　　	handler:function(){
					if (ctxItem.id != "managehome")
						tabs.remove(ctxItem);
					if (Ext.getCmp('mainpanel').items.length == 0){
						addWindow(managehome);
					}
　　　　　　　	}
　　　　　　},"-",{
//				id: tabs.id + '-refresh',
//				text: '刷新当前页',
//				iconCls:'refresh',
//				handler : function(){ 
//					var o =  Ext.apply({},getCmp(ctxItem.id));
//					tabs.remove(ctxItem);
//					Ext.Msg.alert('',o.id);
//					loadMod({id:o.id,title:o.title,grid:'seats'});

//					tree.
//				}
//			},'-',{
				id: tabs.id + '-close',
				text: '关闭所有',
				iconCls:'remove',
				handler : function(){
					tabs.items.each(function(item){
						if(item.id=="managehome") return;
						tabs.remove(item);
					});
					addWindow(managehome);
				}
			},{
				id: tabs.id + '-close-others',
				text: '关闭其他所有',
				iconCls:'remove',
				handler : function(){
					tabs.items.each(function(item){
						if( item != ctxItem){
							tabs.remove(item);
						}
					});
				}
			}]);
		}
		ctxItem = item;
		var items = menu.items;
		var disableOthers = true;
		tabs.items.each(function(){
			if(this != item){
				disableOthers = false;
				return false;
			}
		});
		items.get(tabs.id + '-close-others').setDisabled(disableOthers);
		menu.showAt(e.getPoint());
	}
};

//定义新窗口添加函数
function addWindow(obj){
	var tabId = (obj.id)?obj.id:"managehome";
	var aTab;
	var mainpanel = Ext.getCmp('mainpanel');
	if(!mainpanel.getItem(tabId)){
		mainpanel.add(obj);
	}
	mainpanel.setActiveTab(mainpanel.getItem(tabId));
}

zyt.Permit = function(){
	zyt.ajax(serverUrl_Permit + "?key=" + now(),{action:'permit'}, function(result) {
		if(result === "permit"){
			var permitWindow = new PermitWindow({url:serverUrl_Login,redirect: de});
			permitWindow.showLogin();
			Ext.getCmp('loginUserName').focus(true,true);
		}
	});
};


zyt.getSysUser = function(){
	zyt.ajax(serverUrl_UserGet + '?getuser&key='+now(),{action:'getuser'},function(result){
		var rec = result.split('^');
		
		if(rec[1]>0) {
			//Ext.get('user').dom.innerHTML = '<span class="fontred"><b>共有 ' + rec[1] + ' 笔待发货订单！</b></span>&nbsp;&nbsp;' + Ext.get('user').dom.innerHTML;
			top.document.getElementById('se_o_alarm').src = '/img/alarm.wav';
		}
	})
};